package cn.sinjet.model.mcuupgrade;

public class MCUUpgradeCommonFunction {
	public static int getUnsignedByte (byte data){      //锟斤拷data锟街斤拷锟斤拷锟斤拷锟阶拷锟轿�~255 (0xFF 锟斤拷BYTE)锟斤拷
		return data&0x0FF;
	}

	public static int getUnsignedShort (short data){      //锟斤拷data锟街斤拷锟斤拷锟斤拷锟阶拷锟轿�~65535 (0xFFFF 锟斤拷 WORD)锟斤拷
		return data&0x0FFFF;
	}       

	public static long getUnsignedInt (int data){     //锟斤拷int锟斤拷锟阶拷锟轿�~4294967295 (0xFFFFFFFF锟斤拷DWORD)锟斤拷
		return data&0x0FFFFFFFFl;
	}
	
	public static int transVersionToInt (byte[] version) {
		if (version == null || version.length == 0) {
			return 0;
		}
		
		int versionValue = 0;
		for (int i = 0;i < 8;i++) {
			if (0 == version[i]) {
				break;
			}
			else {
				versionValue *= 10;
				versionValue += version[i] - '0';
			}
		}
		return versionValue;
	}
	
	public static boolean equalArraySelectLength(byte[] array1,byte[] array2,int length)
	{
        if (array1 == array2) {
            return true;
        }
        if (array1 == null || array2 == null) {
            return false;
        }
        for (int i = 0; i < length; i++) {
            if (array1[i] != array2[i]) {
                return false;
            }
        }
        return true;	
	}
}
